home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gnushogi.lha / gnushogi-1.1 / src / size_test.c < prev    next >
C/C++ Source or Header  |  1993-04-16  |  7KB  |  277 lines

  1. /*
  2.  * main.c - C source for GNU SHOGI based on GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback (GNU Chess)
  5.  * Copyright (c) 1992 Free Software Foundation 
  6.  * Copyright (c) 1993 Matthias Mutz (GNU Shogi)
  7.  *
  8.  * This file is part of GNU SHOGI.
  9.  *
  10.  * GNU Shogi is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 1, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Shogi is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Shogi; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25.  
  26. #if !defined NO_MAIN
  27.  
  28. #include "version.h"
  29. #include "gnushogi.h"
  30.  
  31. #endif
  32.  
  33. #include <signal.h>
  34.  
  35. #if defined THINK_C
  36. #include <console.h>
  37. #include <time.h>
  38. #endif
  39.  
  40. #if !defined K32SEGMENTS
  41. #include "main_data1.c"
  42. #include "main_data2.c"
  43. #endif
  44.  
  45.  
  46. #if defined HASGETTIMEOFDAY && defined THINK_C
  47.  
  48. #define USEC_PER_CLOCK (1000000 / CLOCKS_PER_SEC)
  49.  
  50. int gettimeofday(struct timeval *tp, void *tzp)
  51.    long clock_count = (long)clock();
  52.    tp->tv_sec = clock_count / CLOCKS_PER_SEC;
  53.    tp->tv_usec = (clock_count % CLOCKS_PER_SEC) * USEC_PER_CLOCK;
  54.    return(0);
  55. }
  56.  
  57. #endif
  58.  
  59. /*
  60.  * In a networked enviroment gnuchess might be compiled on different hosts
  61.  * with different random number generators, that is not acceptable if they
  62.  * are going to share the same transposition table.
  63.  */
  64. unsigned long int next = 1;
  65.  
  66. unsigned int
  67. urand (void)
  68. {
  69.   next *= 1103515245;
  70.   next += 12345;
  71.   return ((unsigned int) (next >> 16) & 0xFFFF);
  72. }
  73.  
  74. void
  75. gsrand (unsigned int seed)
  76. {
  77.   next = seed;
  78. }
  79.  
  80. #if ttblsz
  81. struct hashentry huge *ttable[2];
  82. unsigned int ttblsize;
  83. #endif
  84. #ifdef BINBOOK
  85. extern char *binbookfile;
  86. #endif
  87. extern char *bookfile;
  88.  
  89. unsigned long hashkey, hashbd;
  90. struct hashval hashcode[2][NO_PIECES][NO_SQUARES+(2*NO_PIECES)];
  91.  
  92. char savefile[128] = "";
  93. char listfile[128] = "";
  94.  
  95. #if defined HISTORY
  96. unsigned short *history;
  97. #endif
  98.  
  99. short rpthash[2][256];
  100. short TrPnt[MAXDEPTH];
  101. small_short PieceList[2][NO_SQUARES];
  102. small_short PawnCnt[2][NO_COLS];
  103. small_short Captured[2][NO_PIECES];
  104. small_short Mvboard[NO_SQUARES];
  105. short svalue[NO_SQUARES];
  106. struct flags flag;
  107.  
  108. short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
  109.   BADscore;
  110. long ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
  111. long GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt, HashAdd, FHashCnt, FHashAdd,
  112.   HashCol, THashCol, filesz, hashmask, hashbase;
  113. long replus, reminus;
  114. short HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
  115. short player, xwndw;
  116. /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
  117. short Sdepth, Game50, MaxSearchDepth;
  118. short GameCnt = 0;
  119. short contempt;
  120. int Book;
  121. struct TimeControlRec TimeControl;
  122. int TCadd = 0;
  123. short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
  124. short XCmoves[3], XCminutes[3], XCseconds[3], XC, XCmore;
  125. const short otherside[3] =
  126. {white, black, neutral};
  127. unsigned short hint;
  128. short int TOflag;        /* force search re-init if we backup search */
  129.  
  130. unsigned short killr0[MAXDEPTH], killr1[MAXDEPTH];
  131. unsigned short killr2[MAXDEPTH], killr3[MAXDEPTH];
  132. unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
  133.  
  134. const small_short sweep[NO_PIECES] =
  135. {false, false, true,  false, false, false, true, true,
  136.         false, false, false, false, true,  true,  false };
  137. small_short HasPiece[2][NO_PIECES]; 
  138. const short kingP[3] =
  139. {4, 76, 0};
  140. const short value[NO_PIECES] =
  141. {0, valueP,  valueL,  valueN,  valueS,  valueG,  valueB,  valueR,
  142.     valuePp, valueLp, valueNp, valueSp, valueBp, valueRp, valueK}; 
  143. const small_short relative_value[NO_PIECES] =
  144. {0, 1,       3,       4,       7,       9,       10,      12, 
  145.     2,       5,       6,       8,       11,      13,      14};
  146. const long control[NO_PIECES] =
  147. {0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR,
  148.     ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK };
  149.  
  150. short stage, stage2;
  151.  
  152. FILE *hashfile;
  153.  
  154. unsigned int starttime;
  155. short int ahead = true, hash = true;
  156.  
  157.  
  158.  
  159. #if defined XSHOGI
  160. void
  161. TerminateChess (int sig)
  162. {
  163.   ExitChess ();
  164. }
  165.  
  166. #endif
  167.  
  168.  
  169.  
  170. int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
  171. int compptr, oppptr;
  172. inline void
  173. TimeCalc ()
  174. {
  175. /* adjust number of moves remaining in gamein games */
  176.   int increment = 0;
  177.   int topsum = 0;
  178.   int tcompsum = 0;
  179.   int me,him;
  180.   int i;
  181. /* dont do anything til you have enough numbers */
  182.   if (GameCnt < (MINGAMEIN * 2)) return;
  183. /* calculate average time in sec for last MINGAMEIN moves */
  184.   for (i = 0; i < MINGAMEIN; i++)
  185.     {
  186.       tcompsum += timecomp[i];
  187.       topsum += timeopp[i];
  188.     }
  189.   topsum /= (100 * MINGAMEIN);
  190.   tcompsum /= (100 * MINGAMEIN);
  191. /* if I have less time than opponent add another move */
  192.     me = TimeControl.clock[computer]/100; 
  193.     him = TimeControl.clock[opponent]/100;
  194.     if(me < him) increment += 2;
  195.     if((him - me) > 60 || (me<him && me < 120))increment++;
  196. /* if I am losing more time with each move add another */
  197.   /*if ( !((me - him) > 60) && tcompsum > topsum) increment++;*/
  198.   if ( tcompsum > topsum) increment +=2;
  199. /* but dont let moves go below MINMOVES */
  200.   else if (TimeControl.moves[computer] < MINMOVES && !increment) increment++;
  201. /* if I am doing really well use more time per move */
  202.   else if (me > him && tcompsum < topsum) increment = -1;
  203.   TimeControl.moves[computer] += increment;
  204. }
  205.  
  206.  
  207.  
  208.  
  209. #if !defined NO_MAIN
  210.  
  211.  
  212. /* hmm.... shouldn`t main be moved to the interface routines */
  213. int
  214. main (int argc, char **argv)
  215. {
  216.   long l;
  217.   int  n;
  218.  
  219. #ifdef THINK_C
  220.   console_options.ncols = 100;
  221.   cshow(stdout);
  222. #endif
  223.  
  224.   l = (long)sizeof(struct hashentry);
  225.   n = (int)((l * (ttblsz + rehash) * 2) / 1000);
  226.   printf("ttable:\t\t%d\tkByte\t[hashentry:%ld * (ttblsz:%d + rehash:%d) * 2]\n",
  227.      n,l,ttblsz,rehash);
  228.  
  229. #if defined CACHE
  230.   l = (long)sizeof(struct etable);
  231.   n = (int)((l * (size_t)ETABLE) / 1000);
  232. #else
  233.   l = n = 0;
  234. #endif
  235.   printf("etab:\t\t%d\tkByte\t[etable:%ld ETABLE:%d]\n",n,l,ETABLE);
  236.  
  237.   l = (long)sizeof(struct leaf);
  238.   n = (int)(sizeof(Tree) / 1000);
  239.   printf("Tree:\t\t%d\tkByte\t[leaf:%ld * TREE:%d]\n",n,l,TREE);
  240.  
  241. #if defined HISTORY
  242.   n = (int)(sizeof_history / 1000);
  243. #else
  244.   n = 0;
  245. #endif
  246.   printf("history:\t%d\tkByte\n",n);
  247.  
  248.   l = (long)sizeof(next_array);
  249.   n = (int)((l * NO_PTYPE_PIECES) / 1000);
  250.   printf("nextpos:\t%d\tkByte\t[next_array:%ld * NO_PTYPE_PIECES:%d]\n",
  251.     n,l,NO_PTYPE_PIECES);
  252.  
  253.   l = (long)sizeof(next_array);
  254.   n = (int)((l * NO_PTYPE_PIECES) / 1000);
  255.   printf("nextdir:\t%d\tkByte\t[next_array:%ld * NO_PTYPE_PIECES:%d]\n",
  256.     n,l,NO_PTYPE_PIECES);
  257.  
  258.   n = (int)(sizeof(distdata) / 1000);
  259.   printf("distdata:\t%d\tkByte\n",n);
  260.  
  261.   l = (long)sizeof(next_array);
  262.   n = (int)((l * NO_PTYPE_PIECES) / 1000);
  263.   printf("ptype_distdata:\t%d\tkByte\t[next_array:%ld * NO_PTYPE_PIECES:%d]\n",
  264.     n,l,NO_PTYPE_PIECES);
  265.  
  266.   l = (long)sizeof(hashcode);
  267.   n = (int)(l / 1000);
  268.   printf("hashcode:\t%d\tkByte\t[hashval:%ld]\n",
  269.     n,(long)sizeof(struct hashval));
  270.  
  271. }
  272.  
  273.  
  274. #endif /* NO_MAIN */
  275.  
  276.